package feign.ethan.springCloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import feign.ethan.springCloud.serviceImpl.ProducerService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author Ethan
 */
@SpringBootApplication
@EnableEurekaClient


@EnableDiscoveryClient
@EnableAsync
public class SpringCloudApplication8001 {
    public static void main(String[] args) {
        // 获取bean发消息
        //SpringApplication.run(SpringCloudApplication8001.class, args);
        ConfigurableApplicationContext run = SpringApplication.run(SpringCloudApplication8001.class, args);
        ProducerService producerService = (ProducerService) run.getBean("producerService");
        producerService.sendMessage();
    }

    /**
     * 增加ServletRegistrationBean的bean
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");
        return servletRegistrationBean;
    }
}
